home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_300
/
334_01
/
command2.c
< prev
next >
Wrap
Text File
|
1991-02-04
|
28KB
|
1,067 lines
/*
*
* gnutex/gnuplot translator -- command.c
*
* By David Kotz, 1990.
* Department of Computer Science, Duke University, Durham, NC 27706.
* Mail to dfk@cs.duke.edu.
*/
#include <stdio.h>
#include <math.h>
#include "plot.h"
#ifndef STDOUT
#define STDOUT 1
#endif
extern char *malloc();
/*
* global variables to hold status of 'set' options
*
*/
BOOLEAN autoscale_x = TRUE;
BOOLEAN autoscale_y = TRUE;
BOOLEAN autoscale_lx = TRUE; /* local to this plot */
BOOLEAN autoscale_ly = TRUE; /* local to this plot */
enum PLOT_STYLE data_style = POINTS,
func_style = LINES;
BOOLEAN log_x = FALSE,
log_y = FALSE;
FILE* infile;
FILE* outfile;
char outstr[MAX_ID_LEN+1] = "STDOUT";
int samples = SAMPLES;
int term = 0; /* unknown term is 0 */
double xmin = -10,
xmax = 10,
ymin = -10,
ymax = 10;
double zero = ZERO; /* zero threshold, not 0! */
BOOLEAN xtics = TRUE;
BOOLEAN ytics = TRUE;
BOOLEAN clipping = TRUE;
BOOLEAN undefined;
char title_string[MAX_LINE_LEN] = "";
char xlabel_string[MAX_LINE_LEN] = "";
char ylabel_string[MAX_LINE_LEN] = "";
char xformat[MAX_ID_LEN] = "";
char yformat[MAX_ID_LEN] = "";
int y_skip_factor = 0;
double plot_width = 4; /* width in inches, for latex */
double plot_height = 3; /* height in inches, for latex */
/*
* instead of <strings.h>
*/
char *gets(),*getenv();
char *strcpy(),*strcat();
double magnitude(),angle(),real(),imag();
struct value *const_express(), *pop(), *complex();
extern struct vt_entry vt[];
extern struct st_entry st[];
extern struct udft_entry udft[];
extern int inline; /* line number of current input line */
char input_line[MAX_LINE_LEN],dummy_var[MAX_ID_LEN + 1];
struct at_type *curr_at;
int c_token;
int next_value = (int)NEXT_VALUE,next_function = 0,c_function = 0;
int num_tokens;
struct curve_points plot[MAX_PLOTS];
int plot_count = 0;
char plot_ranges[MAX_LINE_LEN+1];
BOOLEAN pending_plot = FALSE; /* TRUE if a plot command is pending output */
int plot_line; /* input line number of pending plot */
BOOLEAN key_on = TRUE; /* will a key be displayed */
BOOLEAN plot_key = FALSE; /* did we want a key for this plot? */
BOOLEAN label_on = FALSE; /* will labels be displayed */
BOOLEAN arrow_on = FALSE; /* will arrows be displayed */
BOOLEAN plot_label = FALSE; /* do we want labels displayed? */
BOOLEAN plot_arrow = FALSE; /* do we want arrows displayed? */
BOOLEAN plot_format = FALSE; /* have we seen a set format? */
BOOLEAN was_output; /* was there any output from command? */
int inline = 0; /* input line number */
com_line()
{
read_line();
#ifdef vms
if (input_line[0] == '!' || input_line[0] == '$')
fprintf(outfile, "%s\n", input_line);
else
do_line();
#else /* vms */
if (input_line[0] == '!')
fprintf(outfile, "%s\n", input_line);
else
do_line();
#endif
}
/* Read a line of input; much simplified by the fact that infile is
* never a terminal. Handles line continuation and EOF.
*/
read_line()
{
int len, left;
int start = 0;
BOOLEAN more, stop;
int last;
/* read one command */
left = MAX_LINE_LEN;
start = 0;
more = TRUE;
stop = FALSE;
while (more) {
if (fgets(&(input_line[start]), left, infile) == NULL) {
stop = TRUE; /* EOF in file */
input_line[start] = '\0';
more = FALSE;
} else {
inline++;
len = strlen(input_line) - 1;
if (input_line[len] == '\n') { /* remove any newline */
input_line[len] = '\0';
len--;
} else if (len+1 >= left)
int_error("Input line too long",NO_CARET);
if (input_line[len] == '\\') { /* line continuation */
start = len;
left -= len;
} else
more = FALSE;
}
}
if (stop && input_line[0] == '\0')
done(0);
}
do_line()
{
extern int comment_pos; /* from scanner */
BOOLEAN nonempty; /* TRUE if output was nonempty */
num_tokens = scanner(input_line);
c_token = 0;
nonempty = FALSE;
while(c_token < num_tokens) {
was_output = FALSE;
command(); /* parse the next command */
if (c_token < num_tokens) /* something after command */
if (equals(c_token,";")) {
c_token++;
if (was_output)
fprintf(outfile, "; ");
} else
int_error("';' expected",c_token);
nonempty = was_output || nonempty;
}
/* write out any comment */
if (comment_pos >= 0) {
if (nonempty)
putc(' ', outfile);
fputs(input_line+comment_pos, outfile);
nonempty = TRUE;
}
if (nonempty || num_tokens == 0)
putc('\n', outfile);
}
command()
{
int start_token = c_token;
if (is_definition(c_token)) {
define();
copy_command(start_token, c_token-1);
}
else if (almost_equals(c_token,"h$elp") || equals(c_token,"?")) {
c_token++;
while (!(END_OF_COMMAND))
c_token++;
err_msg("help command ignored (removed)");
}
else if (almost_equals(c_token,"pr$int")) {
struct value a;
c_token++;
(void) const_express(&a);
copy_command(start_token, c_token-1);
}
else if (almost_equals(c_token,"p$lot")) {
if (pending_plot)
write_plot();
c_token++;
plotrequest();
pending_plot = TRUE;
plot_line = inline;
/* we defer output until eof or next plot command */
}
else if (almost_equals(c_token,"la$bel")) {
c_token++;
labelrequest();
}
else if (almost_equals(c_token,"k$ey")) {
c_token++;
keyrequest();
}
else if (almost_equals(c_token,"se$t")) {
c_token++;
if (almost_equals(c_token,"t$erminal")) {
c_token++;
if (!END_OF_COMMAND)
c_token++;
copy_command(start_token, c_token-1);
}
else if (almost_equals(c_token,"sa$mples")) {
struct value a;
c_token++;
(void)magnitude(const_express(&a));
copy_command(start_token, c_token-1);
}
else if (almost_equals(c_token,"o$utput")) {
c_token++;
if (!END_OF_COMMAND) { /* no file specified */
if (!isstring(c_token))
int_error("expecting filename",c_token);
else
c_token++;
}
copy_command(start_token, c_token-1);
}
else if (almost_equals(c_token,"a$utoscale")) {
c_token++;
if (END_OF_COMMAND) {
} else if (equals(c_token, "xy") || equals(c_token, "yx")) {
c_token++;
} else if (equals(c_token, "x")) {
c_token++;
} else if (equals(c_token, "y")) {
c_token++;
} else
int_error("expecting axes specification", c_token);
copy_command(start_token, c_token-1);
}
else if (almost_equals(c_token,"noa$utoscale")) {
c_token++;
if (END_OF_COMMAND) {
} else if (equals(c_token, "xy") || equals(c_token, "yx")) {
c_token++;
} else if (equals(c_token, "x")) {
c_token++;
} else if (equals(c_token, "y")) {
c_token++;
} else
int_error("expecting axes specification", c_token);
copy_command(start_token, c_token-1);
}
else if (almost_equals(c_token,"l$ogscale")) {
c_token++;
if (equals(c_token,"x")) {
c_token++;
} else if (equals(c_token,"y")) {
c_token++;
} else if (equals(c_token,"xy") || equals(c_token,"yx")) {
c_token++;
} else
int_error("expecting 'x', 'y', or 'xy'", c_token);
copy_command(start_token, c_token-1);
}
else if (almost_equals(c_token,"nol$ogscale")) {
copy_command(start_token, c_token++);
}
else if (almost_equals(c_token,"z$ero")) {
struct value a;
c_token++;
(void) magnitude(const_express(&a));
copy_command(start_token, c_token-1);
}
else if (almost_equals(c_token,"x$range")) {
c_token++;
if (!equals(c_token,"["))
int_error("expecting '['",c_token);
c_token++;
load_range();
if (!equals(c_token,"]"))
int_error("expecting ']'",c_token);
c_token++;
copy_command(start_token, c_token-1);
}
else if (almost_equals(c_toke